/**
 * 位图传参
 * 系统调用open参数flags原理
 */

#include <stdio.h>

#define print1 (1 << 0) //0001
#define print2 (1 << 1) //0010
#define print3 (1 << 2) //0100
#define print4 (1 << 3) //1000

void print_by_flag(int flags)
{
    if(flags & print1) printf("hello 1\n");
    if(flags & print2) printf("hello 2\n");
    if(flags & print3) printf("hello 3\n");
    if(flags & print4) printf("hello 4\n");
}

int main()
{
    //通过宏，可以批量化向函数传递多个标志位，函数仅用一个参数即可接收
    print_by_flag(print1);
    print_by_flag(print1 | print2);
    print_by_flag(print2 | print3 | print4);
    print_by_flag(print1 | print4);
    print_by_flag(print3);

    return 0;
}
